﻿@model GsifWeb4.ViewModels.MatchesToEditViewModel

<h2>Välj år</h2>
<div>
    @using (Html.BeginForm())
    {
        @Html.DropDownList("Year", new SelectList(Model.Years))
        <input type="submit" value="Visa" />
    }

    <table>

        @{
            int currentYear = -1;
            foreach (var match in Model.Matches.OrderByDescending(m => m.Datum))
            {
                if (currentYear != match.Datum.Value.Year)
                {
                    currentYear = match.Datum.Value.Year;
            <tr>
                <td colspan="9"><b>@currentYear</b></td>
            </tr>      
                } 
            <tr>
                <td>@match.Datum.Value.ToString("yyyy-MM-dd")</td>
                <td>
                    @if (match.Typ.ToLower() == "serie")
                    {
                        <text>Omgång: @match.Omgang</text>
                    }
                    else if (match.Typ.ToLower() == "träning")
                    {
                        <text>Träningsmatch</text>
                    }
                    else 
                    {
                        <text>@match.Typ</text>
                    }
                </td>
                <td>
                    @if (GsifWeb4.StatExist.Yes.IsDbValue(match.StatExcist))
                    { 
                        @Html.ActionLink(@match.Lag + "-" + @match.Motstandare, "Details", new { ID = match.MaId })
                    }
                    else
                    {
                        <text>@match.Lag - @match.Motstandare</text>
                    }
                </td>
                <td>
                    @if (GsifWeb4.StatExist.Yes.IsDbValue(match.StatExcist))
                    {
                        <text>@match.Resultat (@match.Plan)</text>
                    }
                    else
                    {
                        @Html.ActionLink("Lägg till matchreferat", "AddMatchReport", new { ID = match.MaId })
                    }
                </td>
                <td>
                    @if (GsifWeb4.StatExist.Yes.IsDbValue(match.StatExcist))
                    { 
                        @Html.ActionLink("Uppdatera matchreferat", "UpdateMatchReport", new { ID = match.MaId })
                    }

                </td>
                @if (Model.LoggedInPlayer.AllowedToWebRed())
                { 
                    <td>
                        @match.MaId
                    </td>
                }
            </tr>
            }
        }
    </table>
</div>

<div id="matchesToEdit">
</div>

